//
//  VCOfIntroduction.m
//  XYFMApp
//
//  Created by 岁变 on 16/9/5.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "VCOfIntroduction.h"
#import "XYMacro.h"

@interface VCOfIntroduction () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UIImageView *picImageVew;
@property (nonatomic, strong) BaseCollectionView *collectionView;
@property (nonatomic, strong) NSArray *titleArr;
@property (nonatomic, strong) UILabel *labelIntroduction;
@property (nonatomic, strong) UILabel *labelContent;
@property (nonatomic, strong) NSString *ContentString;

@end

@implementation VCOfIntroduction

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _titleArr = [_model.data.item_tags componentsSeparatedByString:@","];
    
    [self configNavigationController];
    [self configViewController];
}

- (void)configNavigationController {
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.09 green:0.10 blue:0.13 alpha:1.00];
    self.title = @"简介";
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    UIButton *goBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
    goBackButton.frame = CGRectMake(0, 0, 30, 30);
    [goBackButton setImage:[UIImage imageNamed:@"go_back"] forState:UIControlStateNormal];
    [goBackButton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:goBackButton];
    self.navigationItem.leftBarButtonItem = leftItem;
}

- (void)configViewController {
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    backView.backgroundColor = [UIColor colorWithRed:0.09 green:0.10 blue:0.13 alpha:1.00];
    [self.view addSubview:backView];
    
    _picImageVew = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 430)];
    [_picImageVew sd_setImageWithURL:[NSURL URLWithString:_model.data.item_img] placeholderImage:PLACEHOLDERIMAGE];

    [backView addSubview:_picImageVew];
    
    UIView *lineViewOne = [[UIView alloc] initWithFrame:CGRectMake(0, 438, SCREEN_WIDTH, 2)];
    lineViewOne.backgroundColor = [UIColor grayColor];
    [backView addSubview:lineViewOne];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 445, 50, 30)];
    label.text = @"标签:";
    label.textColor = [UIColor whiteColor];
    [backView addSubview:label];
    
    UIView *lineViewTwo = [[UIView alloc] initWithFrame:CGRectMake(0, 480, SCREEN_WIDTH, 1)];
    lineViewTwo.backgroundColor = [UIColor colorWithRed:0.98 green:0.19 blue:0.00 alpha:1.00];
    [backView addSubview:lineViewTwo];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _collectionView = [[BaseCollectionView alloc] initWithFrame:CGRectMake(80, 445, SCREEN_WIDTH - 35, 30) collectionViewLayout:layout];
    _collectionView.backgroundColor = [UIColor colorWithRed:0.09 green:0.10 blue:0.13 alpha:1.00];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.showsHorizontalScrollIndicator = NO;
    [_collectionView registerClass:[IntroductionCollectionViewCellFirst class] forCellWithReuseIdentifier:@"pool"];
    [backView addSubview:_collectionView];
    
    _labelIntroduction = [[UILabel alloc] initWithFrame:CGRectMake(30, 485, 100, 30)];
    _labelIntroduction.text = @"栏目简介:";
    _labelIntroduction.textColor = [UIColor whiteColor];
    [backView addSubview:_labelIntroduction];
    
    
    CGRect newRect = [_ContentString boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 70, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15]} context:nil];

    _labelContent = [[UILabel alloc] initWithFrame:CGRectMake(35, 520, SCREEN_WIDTH - 70, newRect.size.height)];
    _labelContent.text = _ContentString;
    _labelContent.textColor = [UIColor whiteColor];
    _labelContent.numberOfLines = 0;
    _labelContent.font = [UIFont systemFontOfSize:15];
    [backView addSubview:_labelContent];
    
    UIView *lineViewThree = [[UIView alloc] initWithFrame:CGRectMake(0, 520 + newRect.size.height + 10, SCREEN_WIDTH, 2)];
    lineViewThree.backgroundColor = [UIColor colorWithRed:0.20 green:0.21 blue:0.24 alpha:1.00];
    [backView addSubview:lineViewThree];
    
    
}



- (void)goBack:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _titleArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    IntroductionCollectionViewCellFirst *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor colorWithRed:0.09 green:0.10 blue:0.13 alpha:1.00];
    
    cell.logoLabel.text = [_titleArr objectAtIndex:indexPath.row];
    return cell;
    
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    NSString *text = [_titleArr objectAtIndex:indexPath.row];
    CGRect newRect = [text boundingRectWithSize:CGSizeMake(0, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15]} context:nil];
    
    CGSize newSize = CGSizeMake(newRect.size.width + 5, 25);
    return newSize;
}


- (void)setModel:(DiscoverListModelFirst *)model {
    
    _model = [[DiscoverListModelFirst alloc] init];
    _model = model;
    
    _ContentString = _model.data.item_desc;
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
